package top.xana.acg.common.base.adp

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import com.alibaba.android.vlayout.DelegateAdapter
import com.alibaba.android.vlayout.LayoutHelper

/**
 * Created by xana on 2022/3/22 0022
 * Describe: cv4096@qq.com
 */
open class BaseDelegateAdapter(private val layoutHelper:
LayoutHelper, private val layoutId: Int, private val count: Int) : DelegateAdapter.Adapter<BaseViewHolder>() {
    /* 创建ViewHolder */

    protected var ctx: Context? = null
    protected var inflater: LayoutInflater? = null
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder {
        if(ctx==null) ctx = parent.context
        if(inflater==null) inflater = LayoutInflater.from(ctx)
        val v = inflater!!.inflate(layoutId, parent, false)
        return BaseViewHolder(v)
    }
    /* 绑定ViewHolder */
    override fun onBindViewHolder(holder: BaseViewHolder, position: Int) {
    }
    /* 多少个Item */
    override fun getItemCount(): Int {
        return count
    }
    /* LayoutHelper */
    override fun onCreateLayoutHelper(): LayoutHelper {
        return layoutHelper
    }

}